package com.yl.demo.utils;

import com.google.gson.Gson;

/**
 * Created by YL on 2019/10/17.
 */
public class BaseUtil {

    public static String toJSON(Object obj, Class<?>... skipClass){
        String json = null;
        try {
            Gson gson = GSONUtil.getGson(skipClass);
            json = gson.toJson(obj);
            return json;
        } catch (Exception e) {
            return "{}";
        }
    }

    protected final <T> T fromJSON(String json, Class cls) {
        if (json == null || json.isEmpty()) {
            return null;
        }
        return (T) GSONUtil.getGson().fromJson(json, cls);
    }
}
